package edu.szu.huhanpeng.doodlingFight.view 
{
	import com.bit101.components.Panel;
	import com.bit101.components.Text;
	import edu.szu.huhanpeng.doodlingFight.globalConst.GlobalConst;
	import edu.szu.huhanpeng.doodlingFight.interfaces.IChessData;
	import edu.szu.huhanpeng.doodlingFight.view.components.ChessComponent;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.utils.Dictionary;
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.interfaces.INotifier;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author Huhanpeng
	 */
	public class ChessBoardMed extends Mediator implements IMediator, INotifier 
	{
		
		public static const NAME:String = "ChessBoardMed";
		
		/////////////////////////////////////////////////////////////////////
		//getter setter                                                    //
		/////////////////////////////////////////////////////////////////////
		
		
       		
		
		/////////////////////////////////////////////////////////////////////
		//构造函数                                                         //
		/////////////////////////////////////////////////////////////////////
		
		public function ChessBoardMed() 
		{
			var sprite:Sprite = new Sprite();
			super( NAME, sprite );
		}		
		
		
		/////////////////////////////////////////////////////////////////////
		//接口                                                             //
		/////////////////////////////////////////////////////////////////////
		
		public function addChess(child:DisplayObject):DisplayObject
		{
			return chessBoard.addChild(child);
		}
		
		public function getChessByName(name:String):DisplayObject
		{
			return chessBoard.getChildByName( name );
		}	
		
		public function removeChessByName(name:String):DisplayObject
		{
			var chess:DisplayObject = chessBoard.getChildByName( name );
			return chessBoard.removeChild( chess );
		}	
		
		override public function listNotificationInterests():Array 
		{
			return [GlobalConst.noteName.REMOVE_CHESS,
					GlobalConst.noteName.ADD_CHESS];
		}
		
		override public function handleNotification(note:INotification):void 
		{
			super.handleNotification( note );
			switch ( note.getName() ) 
			{
				case GlobalConst.noteName.REMOVE_CHESS:
					var chessName:String = (note.getBody() as IChessData).name;
					removeChessByName( chessName );
				break;
				
				case GlobalConst.noteName.ADD_CHESS:
					var chess:DisplayObject = note.getBody() as DisplayObject;
					addChess( chess );
				default:
			}
		}
		
		/////////////////////////////////////////////////////////////////////
		//内部                                                             //
		/////////////////////////////////////////////////////////////////////
		
		protected function get chessBoard():Sprite
		{
			return viewComponent as Sprite;
		}
		
	}

}